<template>
  <div class="tag-factory-result">
    <div class="story-box">
      <div class="story-title linear-blue">
        <span class="icon"><icon-svg name="iconCalculateResult"></icon-svg></span><br />
        运行结果
      </div>
      <div class="story-content">
        <div class="result-title">
          <el-row>
            <el-col :span="9" align="center">
              <span>命中客户数（人）</span>
            </el-col>
            <el-col :span="5" align="center">
              <span>创建方式</span>
            </el-col>
            <el-col :span="5" align="center">
              <span>运行结果</span>
            </el-col>
            <el-col :span="5" align="center">
              <span>计算时间</span>
            </el-col>
          </el-row>
        </div>
        <div class="result-content tag-scrollbar">
          <el-row>
            <el-col :span="9" align="center">
              <el-row :gutter="50">
                <el-col :span="12" align="right">
                  <tag-progress
                    type="circle"
                    :percentage="percentage"
                    :behindStrokeWidth="5"
                    :gapWidth="2"
                    stroke-linecap="square"
                    color="#007aff"
                    bebindColor="#e9f0f7"
                    class="quality-progress"
                    :width="100"
                  >
                    <div slot="content" class="quality-inner-text">
                      <p>{{ percentage }}%</p>
                    </div>
                  </tag-progress>
                </el-col>
                <el-col :span="12" align="left">
                  <div class="result-total">
                    <p>{{ derivedTagData.grpTotal }}</p>
                    在全部用户中占比{{ percentage }}%
                  </div>
                </el-col>
              </el-row>
            </el-col>
            <el-col :span="5" align="center">
              <div class="result-section">{{ isImport ? '客群画像---导入创建' : '客群画像---逻辑创建' }}</div>
            </el-col>
            <el-col :span="5" align="center">
              <div class="result-section">成功</div>
            </el-col>
            <el-col :span="5" align="center">
              <div class="result-section">{{ derivedTagData.runDat }}</div>
            </el-col>
          </el-row>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    derivedTag: {
      type: String,
      required: true
    },
    isImport: {
      type: Boolean,
      default: false
    }
  },
  computed: {
    derivedTagData() {
      return JSON.parse(this.derivedTag)
    }
  },
  watch: {
    derivedTagData() {
      this.percentage = Number(((this.derivedTagData.grpTotal / this.custNum) * 100).toFixed(2))
    }
  },
  created() {
    this.getCustNum()
  },
  data() {
    return {
      custNum: 0,
      percentage: 0
    }
  },
  methods: {
    getCustNum() {
      this.$ajax({
        url: this.$ajax.setUrl('tagFactory/getAllCustNum'),
        method: 'get',
        params: this.$ajax.setParams()
      }).then(({ data }) => {
        if (data && data.code === '0') {
          this.custNum = data.data
          this.percentage = Number(((this.derivedTagData.grpTotal / this.custNum) * 100).toFixed(2))
        } else {
          // 失败后执行的操作
        }
      })
    }
  }
}
</script>

<style lang="scss">
.tag-factory-result {
  .story-box {
    margin-top: 20px;
    height: 180px;
    border-radius: 5px;
    box-shadow: 1px 1px 3px #ddd, -1px -1px 3px #ddd;
    overflow: hidden;
    position: relative;
  }
  .story-title {
    font-size: 17px;
    font-weight: bold;
    font-weight: bold;
    width: 200px;
    height: 100%;
    color: #fff;
    text-align: center;
    position: relative;
    &:before {
      width: 100%;
      height: 100%;
      content: '';
      position: absolute;
      top: 0;
      left: 0;
      background: url(~@/assets/img/params_bg.png) no-repeat 0px 0px/100% 100%;
    }
  }
  .icon {
    display: inline-block;
    width: 80px;
    height: 80px;
    background-color: #fff;
    margin: 40px 0 10px;
    border-radius: 50%;
    svg {
      width: 50px;
      height: 50px;
      margin-top: 15px;
    }
  }
  .linear-orange {
    background: linear-gradient(to bottom, #f3bf7c, #f3b172);
    svg {
      color: #f3b172;
    }
  }
  .linear-blue {
    background: linear-gradient(to bottom, #63a3fc, #5188ec);
    svg {
      color: #5188ec;
    }
  }
  .story-content {
    padding-left: 200px;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
  }
  .story-text {
    padding: 13px 15px 13px 215px;
    .el-textarea.is-disabled .el-textarea__inner {
      color: #666;
      cursor: default;
    }
  }
  .result-title {
    font-weight: bolder;
    height: 60px;
    border-bottom: 1px solid #eee;
    span {
      display: inline-block;
      width: 80%;
      height: 40px;
      line-height: 40px;
      margin: 10px 0 10px 0;
      background-color: #fcf5e5;
      border-radius: 20px;
    }
  }
  .result-content {
    height: calc(100% - 60px);
    overflow-y: auto;
    li {
      height: 40px;
      line-height: 40px;
    }
  }
  .result-total {
    width: 80%;
    font-size: 14px;
    text-align: center;
    p {
      font-size: 25px;
      font-weight: bold;
      color: #4d82e9;
      margin: 30px 0 10px;
    }
  }
  .result-section {
    font-size: 16px;
    font-weight: bold;
    color: $tag-green;
    margin-top: 50px;
  }
  .el-progress {
    margin-top: 10px;
  }
}
</style>
